<?php

use Doraemon\tools\ActionLog;
use Doraemon\model\AdmUserType;
use Doraemon\service\AdmUserTypeService\AdmUserTypeService;

/**
 *
 * Created by PhpStorm
 * Date: 2022/9/21
 * Time: 18:37
 * docs:
 */
class UserB1Action extends ActionPlugin
{

    public function main()
    {
        \Doraemon\tools\Log::info('UserB1操作接收到的订阅消息', $this->messageBody);

        $data = $this->messageBody['data'];
        $uid = $data['uid'] ?? 0;

        if (!$uid) {
            throw new \Exception('数据错误！');
        }

        $type = $data['quality'] ?? '';

        if (!in_array($type, AdmUserTypeService::SET_ARR)) {
            throw new \Exception('参数错误！');
        }

        if ($type == AdmUserType::B1) {
            AdmUserTypeService::setUserB1($uid);
        } else {
            AdmUserTypeService::cancelUserB1($uid);
        }

        $this->setSuccess();

        ActionLog::log($uid, json_encode($this->messageBody), ActionLog::USER_FLOW);
    }
}